package com.ssy.bus.controller;

import com.ssy.bus.pojo.DrugInfo;
import com.ssy.bus.service.IDrugInfoService;
import com.ssy.bus.service.IProductionService;
import com.ssy.bus.vo.DrugInfoVo;
import com.ssy.common.Constant;
import com.ssy.common.utils.PageResult;
import com.ssy.common.utils.Result;
import com.ssy.system.service.ICommonTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author ssy
 * 药品信息维护
 */
@RestController
@RequestMapping("/drugInfo")
public class DrugInfoController {

    @Autowired
    private IDrugInfoService drugInfoService;

    @Autowired
    private ICommonTypeService commonTypeService;

    @Autowired
    private IProductionService productionService;

    /**
     * 药品信息的分页查询
     *
     * @param drugInfoVo
     * @return
     */
    @GetMapping("/loadAllDrugInfoPage")
    public PageResult loadAllDrugInfoPage(DrugInfoVo drugInfoVo) {
        return this.drugInfoService.loadAllDrugInfoPage(drugInfoVo);
    }

    /**
     * 添加药品信息
     *
     * @param drugInfo
     * @return
     */
    @PostMapping("/addDrugInfo")
    public Result addDrugInfo(@RequestBody DrugInfo drugInfo) {
        return this.drugInfoService.insertDrugInfo(drugInfo);
    }

    /**
     * 修改药品信息
     *
     * @param drugInfo
     * @return
     */
    @PostMapping("/updateDrugInfo")
    public Result updateDrugInfo(@RequestBody DrugInfo drugInfo) {
        return this.drugInfoService.updateDrugInfo(drugInfo);
    }

    /**
     * 删除药品信息
     *
     * @param id
     * @return
     */
    @DeleteMapping("/deleteDrugInfo/{id}")
    public Result deleteDrugInfo(@PathVariable Integer id) {
        return this.drugInfoService.deleteDrugInfoById(id);
    }

    /**
     * 批量删除药品信息
     *
     * @param ids
     * @return
     */
    @DeleteMapping("/bathDeleteDrugInfo/{ids}")
    public Result bathDeleteDrugInfo(@PathVariable Integer[] ids) {
        return this.drugInfoService.bathDeleteDrugInfo(ids);
    }

    /**
     * 修改药品信息状态
     *
     * @param id
     * @param state
     * @return
     */
    @PostMapping("/updateDrugInfoState/{id}/{state}")
    public Result updateDrugInfoState(@PathVariable Integer id, @PathVariable Integer state) {
        DrugInfo drugInfo = new DrugInfo();
        drugInfo.setId(id);
        drugInfo.setState(state);
        return this.drugInfoService.updateDrugInfo(drugInfo);
    }

    /**
     * 加载药品类型的下拉框
     *
     * @return
     */
    @GetMapping("/loadDrugType")
    public Result loadDrugType() {
        return this.commonTypeService.queryAllCommonType(Constant.DRUG_TYPE);
    }

    /**
     * 加载生产厂家的下拉框
     *
     * @return
     */
    @GetMapping("/loadProduction")
    public Result loadProduction() {
        return this.productionService.selectAllProduction();
    }

    /**
     * 加载处方类型的下拉框
     *
     * @return
     */
    @GetMapping("/loadPreType")
    public Result loadPreType() {
        return this.commonTypeService.queryAllCommonType(Constant.PRE_TYPE);
    }
}
